const express = require("express");
const path = require("path");
const app = express();
const config = {
    port: 3001
};
const indexRouter = require("./routes/index");
const userRouter = require("./routes/user");
const booksRouter = require("./routes/books");

/* middleware-start */
app.use((req,res,next)=>{
    console.log("1 req");
    next();
});
app.use((req,res,next)=>{
    console.log("center req");
    next(new Error("错误"));
});
app.use((req,res,next)=>{
    console.log("2 req");
    res.status(200).send("end_req");
});
app.use(function (err, req, res, next) {
    console.error(err.stack)
    res.status(500).send('Something broke!')
 })
/* middleware-end */

app.set("views",path.join(__dirname,"views"));
app.set("view engine","ejs");
/* router-start */
app.use("/", indexRouter);
app.use("/user", userRouter);
app.use("/books",booksRouter);
/* router-end */
app.listen(config.port, () => {
    console.log("server启动_" + config.port);
});